class Solution {
public:
    void dfs(TreeNode* node,int sum,int target,bool& judge) {
        if (node == NULL) { return ; }
        sum += node->val;
        if (sum == target && !node->left && !node->right) { judge = true; }
        if (node->left) { dfs(node->left, sum, target, judge); }
        if (node->right) { dfs(node->right, sum, target, judge); }
    }
    bool hasPathSum(TreeNode* root, int targetSum) {
        if (!root) { return false; }
        bool judge = false;
        dfs(root, 0, targetSum, judge);
        return judge;
    }
};